<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 02.验证0-255之间的数字

        // 1位数时 0 - 9 \d
        // 2位数时 10 - 99  \d{2}
        // 3位数时  100 - 199   1\d{2} 
        //    200 - 249   ^2[0-4]\d
        //  250 - 255    ^25[0-5]
        var reg = /^(\d|\d{2}|^1\d{2}|^2[0-4]\d|^25[0-5])$/
        var str = '255'
        console.log(reg.test(str))
    </script>
</body>

</html>